import math
import json

class Shape:
    @property
    def area(self):
        raise NotImplementedError('Shape 未实现')

#底乘高除2
# class Triangle(Shape):
#     def __init__(self,a,h):
#         self.a = a
#         self.h = h
#
#     @property
#     def area(self):
#         return self.a * self.h / 2

#海伦公式
class Triangle(Shape):
    def __init__(self,a,b,c):
        self.a = a
        self.b = b
        self.c = c

    @property
    def area(self):
        p = (self.a + self.b + self.c) / 2
        return '{:.1f}'.format(math.sqrt(p * (p - self.a) * (p - self.b) * (p - self.c)))


class Rectangle(Shape):
    def __init__(self,a,h):
        self.a = a
        self.h = h

    @property
    def area(self):
        return '{:.1f}'.format(self.a * self.h)

class Circle(Shape):
    def __init__(self,r):
        self.r = r

    @property
    def area(self):
        return '{:.1f}'.format(math.pi * (self.r ** 2))

t = Triangle(3,4,5)
print(t.area)

r = Rectangle(3.4,4.2)
print(r.area)

c = Circle(3)
print(c.area)

print('#' * 30)

#装饰器
# def ser(cls):
#     def _serialzation(self):
#         return json.dumps(self.__dict__)
#     cls.serialzation = _serialzation
#     return cls
#
# @ser
# class SerCirMixIn(Circle):
#     pass
#
# sc = SerCirMixIn(3)
# print(sc.area)
# print(sc.__dict__)
# print(sc.serialzation())


#MixIn
class SerializableMixIn:
    @property
    def serialzation(self):
        return json.dumps(self.__dict__)

class SerCirMixIn(SerializableMixIn,Circle):
    pass

sc = SerCirMixIn(3)
print(sc.area)
print(sc.__dict__)
print(sc.serialzation)
print(SerCirMixIn.mro())

# 完成的不错
